"""PAMR Plot Cross Validataion

.. helpdoc::
Plot Cross Validated PAMR Fits.
"""

"""<widgetXML>
    <name>PAMR Plot Cross Validataion</name>
    <icon></icon>
    <tags>
        <tag>PAMR</tag>
    </tags>
    <summary>Plot Cross Validated PAMR Fits.</summary>
    <author>
        <authorname>Kyle R Covington</authorname>
        <authorcontact>kyle@red-r.org</authorcontact>
    </author>
    </widgetXML>
"""

from OWRpy import * 
import redRGUI 
import libraries.base.signalClasses as signals
import libraries.pamr.signalClasses as pamrSignals
from libraries.base.qtWidgets.graphicsView import graphicsView as redRgraphicsView



class RedRpamr_plotcv(OWRpy): 
    settingsList = []
    def __init__(self, **kwargs):
        OWRpy.__init__(self, **kwargs)
        self.RFunctionParam_fit = ''
        self.require_librarys(["pamr"])
        """.. rrsignals::"""
        self.inputs.addInput("fit", 'Model Fit', pamrSignals.RPAMRCVFit.RPAMRCVFit, self.processfit)
        
        """.. rrgui::"""
        self.plotArea = redRgraphicsView(self.controlArea)
        
        redRGUI.base.commitButton(self.bottomAreaRight, "Commit", callback = self.commitFunction)
    def processfit(self, data):
        
        if data:
            self.RFunctionParam_fit=data.getData()
            #self.data = data
        else:
            self.RFunctionParam_fit=''
    def commitFunction(self):
        if unicode(self.RFunctionParam_fit) == '': 
            self.status.setText('No data to plot')
            return
        self.plotArea.plot(function = 'pamr.plotcv', query = 'fit='+unicode(self.RFunctionParam_fit))

